package com.ncucoder.server.service.impl;

import com.ncucoder.server.mapper.MessageMapper;
import com.ncucoder.server.model.Message;
import com.ncucoder.server.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author <a href="https://www.ncucoder.com">hsowan</a>
 * @since 2019-01-19 08:00
 */
@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MessageMapper messageMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int saveOrUpdate(Message message) {
        return message.getId() != null ? messageMapper.updateById(message) : messageMapper.save(message);
    }
}
